package com.zlx.store.goods.job;

import com.zlx.store.goods.dao.GoodsCategoryDao;
import com.zlx.store.goods.dao.StoreDao;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

@Component
public class WarmUpJob extends QuartzJobBean {
    @Autowired
    private GoodsCategoryDao goodsCategoryDao;
    @Autowired
    private StoreDao storeDao;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        storeDao.selectList(null).forEach(
                store -> {
                    redisTemplate.opsForHash().put("store",String.valueOf(store.getStoreId()),store.getStoreName());}
        );
        goodsCategoryDao.selectList(null).forEach(
                category -> {
                    redisTemplate.opsForHash().put("category",String.valueOf(category.getCategoryId()),category.getCategoryName());}
        );
    }
}
